from django.db import models
# import backend.models as backm

# Create your models here.

class KeyWord(models.Model):
    id = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')
    keyword = models.CharField(max_length=20,unique=True,verbose_name='关键字')
    count = models.IntegerField(default=1,verbose_name="关键词词频")
    class Meta:
        db_table = 'tb_keyword' #指明数据库表名
        verbose_name = '关键字' #在admin站点中显示的名称
        verbose_name_plural = verbose_name #显示的复数名称



class Goods(models.Model):
    id = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')
    link = models.CharField(max_length=250,verbose_name='商品链接')
    price = models.FloatField(verbose_name='价格')
    name = models.CharField(max_length=100,unique=True,verbose_name='名称')
    pic_url = models.CharField(max_length=250,verbose_name='主图链接')
    mall = models.CharField(max_length=10,verbose_name='商城')
    store = models.CharField(max_length=20,verbose_name='店铺名称')
    describe = models.CharField(default='',max_length=100,verbose_name='描述')

    class Meta:
        db_table = 'tb_goods' #指明数据库表名
        verbose_name = '商品' #在admin站点中显示的名称
        verbose_name_plural = verbose_name #显示的复数名称


class GoodsAndKeyWord(models.Model):
    id = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')
    # goodsId = models.IntegerField(verbose_name='商品id')
    goods = models.ForeignKey(Goods,on_delete=models.CASCADE,verbose_name='商品')
    # keywordId = models.IntegerField(verbose_name='关键字id')
    keyword = models.ForeignKey(KeyWord,on_delete=models.CASCADE,verbose_name='关键字')
    class Meta:
        db_table = 'tb_goods_and_keyword' #指明数据库表名
        verbose_name = '商品和关键字' #在admin站点中显示的名称
        verbose_name_plural = verbose_name #显示的复数名称

from backend.models import User
class UserAndGoods(models.Model):
    id = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')
    # userId = models.IntegerField(verbose_name='用户id')
    user = models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='用户')
    # goodsId = models.IntegerField(verbose_name='商品id')
    goods = models.ForeignKey(Goods,on_delete=models.CASCADE,verbose_name='商品')
    relation = models.CharField(max_length=5,verbose_name='关系类型')
    time = models.DateTimeField(auto_now_add=True)
    class Meta:
        db_table = 'tb_user_and_goods' #指明数据库表名
        verbose_name = '用户和商品' #在admin站点中显示的名称
        verbose_name_plural = verbose_name #显示的复数名称
